﻿using System;

namespace AgFractal.Fractals
{
    public class Spider : AbstractFractal
    {
        public Spider()
        {
            Name = Description = "Spider";
            ID = new Guid("32BC58C8-BF01-40d0-B057-1F6178BDF01F");
            R1 = -2.25; I1 = 1.5; R2 = 2.25; I2 = -1.5;
        }

        protected override short Calculate(double r, double i, short MaxIteration)
        {
            short j;
            Complex z = new Complex(r, i);
            Complex z2 = z;            
            for (j = 0; j < MaxIteration; j++)
            {
                if (z.Abs2() > 4) break;
                z = z * z + z2;
                z2 = z + z2 / 2;
            }
            return j;
        }
    }
}